package com.gxa.controller.GlmController;

import com.gxa.service.ExrecordService;
import com.gxa.utils.R;
import com.gxa.vo.*;
import io.swagger.annotations.*;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Api(tags = "消费记录模块")
@RestController
public class ExrecordController {

    @Autowired
    private ExrecordService exrecordService;

    //门诊消费记录

    @ApiOperation(value="门诊消费记录渲染接口",notes="用于点击门诊消费记录时渲染",produces = "application/json",response = R.class)
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "Authorization", value = "令牌", paramType = "header",dataType ="String" ,required = true)
    })
    @ApiResponses(value = {
            @ApiResponse(code = 200, message = "返回门诊消费记录的详细信息",examples = @Example(
                    value = {
                            @ExampleProperty(value = "{'code':200,'msg':'描述'}}", mediaType = "application/json")
                    })),
            @ApiResponse(code = 306, message = "登录已超时，请重新登录"),
            @ApiResponse(code = 307, message = "令牌格式不正确"),
            @ApiResponse(code = 401, message = "没有权限"),
            @ApiResponse(code = 403, message = "无效请求，本系统只支持AJAX请求"),
            @ApiResponse(code = 500, message = "服务器内部错误")
    })
    @RequiresPermissions("cost:sel")
    @GetMapping("/exrecord/queryOutpatient")
    public R queryOutpatient(){
        List<OutexrecordVo> outexrecordVo = this.exrecordService.queryAll();
        System.out.println(outexrecordVo);

       return R.ok().put("data", outexrecordVo);
    }

    @ApiOperation(value="门诊消费记录搜索接口",notes="用于点击搜索门诊消费记录",produces = "application/json",response = R.class)
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "Authorization", value = "令牌", paramType = "header",dataType ="String" ,required = true)
    })
    @ApiResponses(value = {
            @ApiResponse(code = 200, message = "返回门诊消费记录的详细信息",examples = @Example(
                    value = {
                            @ExampleProperty(value = "{'code':200,'msg':'描述'}}", mediaType = "application/json")
                    })),
            @ApiResponse(code = 306, message = "登录已超时，请重新登录"),
            @ApiResponse(code = 307, message = "令牌格式不正确"),
            @ApiResponse(code = 401, message = "没有权限"),
            @ApiResponse(code = 403, message = "无效请求，本系统只支持AJAX请求"),
            @ApiResponse(code = 500, message = "服务器内部错误")
    })
    @RequiresPermissions("cost:sel")
    @PostMapping("/exrecord/selectOutpatient")
    public R selectOutpatient(@ApiParam(name="begintime,endtime,namecard",value = "用于搜索门诊消费记录",required = true)@RequestBody OutexvalueVo outexvalueVo ){

        List<OutexrecordVo> outexrecordVos1 = this.exrecordService.selectAll(outexvalueVo.getBegintime(),outexvalueVo.getEndtime(),outexvalueVo.getNamecard());
        System.out.println(outexrecordVos1);

        return R.ok().put("data", outexrecordVos1);
    }

    @ApiOperation(value="门诊消费记录操作接口",notes="用于点击操作门诊消费记录",produces = "application/json",response = R.class)
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "Authorization", value = "令牌", paramType = "header",dataType ="String" ,required = true)
    })
    @ApiResponses(value = {
            @ApiResponse(code = 200, message = "返回门诊消费记录的详细信息，其中就诊信息不用做",examples = @Example(
                    value = {
                            @ExampleProperty(value = "{'code':200,'msg':'描述'}}", mediaType = "application/json")
                    })),
            @ApiResponse(code = 306, message = "登录已超时，请重新登录"),
            @ApiResponse(code = 307, message = "令牌格式不正确"),
            @ApiResponse(code = 401, message = "没有权限"),
            @ApiResponse(code = 403, message = "无效请求，本系统只支持AJAX请求"),
            @ApiResponse(code = 500, message = "服务器内部错误")
    })
    @RequiresPermissions("cost:sel")
    @PostMapping("/exrecord/oderDetails")
    public R oderDetails(@ApiParam(name="order_num,medcard",value = "订单号,就诊卡号--用于渲染患者和订单详情记录",required = true)@RequestBody DovalueVo dovalueVo){

        //查询订单详情中的患者信息
        List<PatientmsgVo> patientmsgVo = this.exrecordService.queryAllpmsg(dovalueVo.getMedcard());
        List<OrderexmsgVo> orderexmsgVos = this.exrecordService.queryAllomsg(dovalueVo.getOrder_num());

        Map map = new HashMap();

        map.put("patientmsg",patientmsgVo);
        map.put("ordermsg",orderexmsgVos);
        System.out.println(map);
        return R.ok().put("data",map);
    }

    @ApiOperation(value="门诊消费记录订单备注接口",notes="用于点击保存订单备注",produces = "application/json",response = R.class)
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "Authorization", value = "令牌", paramType = "header",dataType ="String" ,required = true)
    })
    @ApiResponses(value = {
            @ApiResponse(code = 200, message = "返回门诊消费记录的详细信息",examples = @Example(
                    value = {
                            @ExampleProperty(value = "{'code':200,'msg':'描述'}}", mediaType = "application/json")
                    })),
            @ApiResponse(code = 306, message = "登录已超时，请重新登录"),
            @ApiResponse(code = 307, message = "令牌格式不正确"),
            @ApiResponse(code = 401, message = "没有权限"),
            @ApiResponse(code = 403, message = "无效请求，本系统只支持AJAX请求"),
            @ApiResponse(code = 500, message = "服务器内部错误")
    })
    @RequiresPermissions("cost:update")
    @PostMapping("/exrecord/updateOrderremark")
    public R updateOrderremark(@ApiParam(name="ordernum,remark",value = "订单备注信息--用于门诊充值记录的订单备注",required = true)@RequestBody OrderexmsgVo orderexmsgVo){

        this.exrecordService.updateRemark(orderexmsgVo.getOrder_num(),orderexmsgVo.getRemark());
        List<OrderexmsgVo> orderexmsgVos = this.exrecordService.queryAllomsg(orderexmsgVo.getOrder_num());
        return R.ok().put("data",orderexmsgVos);
    }




    //住院消费记录————————————————————————————————————————————————————————————————————————————————————————————————————



    @ApiOperation(value="住院消费记录渲染接口",notes="用于点击住院消费记录时渲染",produces = "application/json",response = R.class)
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "Authorization", value = "令牌", paramType = "header",dataType ="String" ,required = true)
    })
    @ApiResponses(value = {
            @ApiResponse(code = 200, message = "返回住院消费记录的详细信息",examples = @Example(
                    value = {
                            @ExampleProperty(value = "{'code':200,'msg':'描述'}}", mediaType = "application/json")
                    })),
            @ApiResponse(code = 306, message = "登录已超时，请重新登录"),
            @ApiResponse(code = 307, message = "令牌格式不正确"),
            @ApiResponse(code = 401, message = "没有权限"),
            @ApiResponse(code = 403, message = "无效请求，本系统只支持AJAX请求"),
            @ApiResponse(code = 500, message = "服务器内部错误")
    })
    @RequiresPermissions("cost:sel")
    @GetMapping("/exrecord/queryHospitalization")
    public R queryHospitalization(){

        List<HosexrecordVo> hosexrecordVos = this.exrecordService.queryAllHos();


        return R.ok().put("data",hosexrecordVos);
    }


    @ApiOperation(value="住院消费记录搜索接口",notes="用于点击搜索住院消费记录",produces = "application/json",response = R.class)
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "Authorization", value = "令牌", paramType = "header",dataType ="String" ,required = true)
    })
    @ApiResponses(value = {
            @ApiResponse(code = 200, message = "返回住院消费记录的详细信息",examples = @Example(
                    value = {
                            @ExampleProperty(value = "{'code':200,'msg':'描述'}}", mediaType = "application/json")
                    })),
            @ApiResponse(code = 306, message = "登录已超时，请重新登录"),
            @ApiResponse(code = 307, message = "令牌格式不正确"),
            @ApiResponse(code = 401, message = "没有权限"),
            @ApiResponse(code = 403, message = "无效请求，本系统只支持AJAX请求"),
            @ApiResponse(code = 500, message = "服务器内部错误")
    })
    @RequiresPermissions("cost:sel")
    @PostMapping("/exrecord/selectHospitalization")
    public R selectHospitalization(@ApiParam(name="begintime,endtime,namehospital",value = "时间，患者名字/住院号--用于搜索住院消费记录",required = true)@RequestBody HosexvalueVo hosexvalueVo){

        List<HosexrecordVo> hosexrecordVos = this.exrecordService.selectAllHos(hosexvalueVo.getBegintime(),hosexvalueVo.getEndtime(),hosexvalueVo.getNamehospital());


        return R.ok().put("data",hosexrecordVos);
    }


    @ApiOperation(value="住院消费记录操作接口",notes="用于点击操作住院消费记录",produces = "application/json",response = R.class)
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "Authorization", value = "令牌", paramType = "header",dataType ="String" ,required = true)
    })
    @ApiResponses(value = {
            @ApiResponse(code = 200, message = "返回住院消费记录的详细信息，其中住院信息不用做",examples = @Example(
                    value = {
                            @ExampleProperty(value = "{'code':200,'msg':'描述'}}", mediaType = "application/json")
                    })),
            @ApiResponse(code = 306, message = "登录已超时，请重新登录"),
            @ApiResponse(code = 307, message = "令牌格式不正确"),
            @ApiResponse(code = 401, message = "没有权限"),
            @ApiResponse(code = 403, message = "无效请求，本系统只支持AJAX请求"),
            @ApiResponse(code = 500, message = "服务器内部错误")
    })
    @RequiresPermissions("cost:sel")
    @PostMapping("/exrecord/oderDetails1")
    public R oderDetails1(@ApiParam(name="order_num，hospital",value = "订单号,住院号--用于搜索住院消费记录",required = true)@RequestBody DohosexVo dohosexVo){

        //查询订单详情中的患者信息

        String querymedcard = this.exrecordService.querymedcard(dohosexVo.getHospital());
        List<PatientmsgVo> patientmsgVo = this.exrecordService.queryAllphosmsg(querymedcard);
        List<OrderexmsgVo> orderexmsgVos = this.exrecordService.queryAllohosmsg(dohosexVo.getOrder_num());

        Map map = new HashMap();



        map.put("patientmsg",patientmsgVo);
        map.put("ordermsg",orderexmsgVos);

        return R.ok().put("data",map);
    }


    @ApiOperation(value="住院消费记录订单备注接口",notes="用于点击保存订单备注",produces = "application/json",response = R.class)
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "Authorization", value = "令牌", paramType = "header",dataType ="String" ,required = true)
    })
    @ApiResponses(value = {
            @ApiResponse(code = 200, message = "返回住院消费记录的详细信息",examples = @Example(
                    value = {
                            @ExampleProperty(value = "{'code':200,'msg':'描述'}}", mediaType = "application/json")
                    })),
            @ApiResponse(code = 306, message = "登录已超时，请重新登录"),
            @ApiResponse(code = 307, message = "令牌格式不正确"),
            @ApiResponse(code = 401, message = "没有权限"),
            @ApiResponse(code = 403, message = "无效请求，本系统只支持AJAX请求"),
            @ApiResponse(code = 500, message = "服务器内部错误")
    })
    @RequiresPermissions("cost:update")
    @PostMapping("/exrecord/updateHosremark")
    public R updateHosremark(@ApiParam(name="ordernum,remark",value = "订单备注信息--用于门诊消费记录的订单备注",required = true)@RequestBody OrderexmsgVo orderexmsgVo){

        this.exrecordService.updateRemark(orderexmsgVo.getOrder_num(),orderexmsgVo.getRemark());
        List<OrderexmsgVo> orderexmsgVos = this.exrecordService.queryAllohosmsg(orderexmsgVo.getOrder_num());
        return R.ok().put("data",orderexmsgVos);
    }

}
